import { View } from "../../../mvc/core/View";
import { SBusiness } from "../../../../Message/Public/SBusiness";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { Cache } from "../../cache/Cache";
import { MsgManager } from "../../manager/MsgManager";
import { Language } from "../../../../extend/language/Language";
import { EffectManager } from "../../manager/EffectManager";
import { UIIconEvent } from "../uiIconBtn/UIIconEvent";
import { Alert } from "../../../../com/mui/controls/Alert";
import { DataEvent } from "../../events/DataEvent";
import { GModuleEvent } from "../../mvc/GModuleEvent";
import { Vector } from "../../../../__AS3__/vec/Vector";
type int = number;
//class TradeHintIcon
    
    export  class TradeHintIcon extends View
    {
        constructor()
        {
            super();
            this._requestList = new Vector.<SBusiness>();
            this.createChildren();
            return;
        }

        /* internal  */createChildren(): void
        {
            this.mouseChildren = false;
            this.hintIcon = new Object /* flash.display.Sprite */();
            this.hintIcon.addChild(GlobalClass.getBitmap("trade_hintIcon"));
            addChild(this.hintIcon);
            this.hintIcon.buttonMode = true;
            this._labelTxt = new Object /* flash.text.TextField */();
            this._labelTxt.selectable = false;
            this._labelTxt.filters = [FilterConst.glowFilter];
            this._labelTxt.width = this.hintIcon.width;
            this._labelTxt.height = 10;
            this._labelTxt.autoSize = flash.text.TextFieldAutoSize.RIGHT;
            addChild(this._labelTxt);
            this._labelTxt.y = this.hintIcon.height - 14;
            this._labelTxt.mouseEnabled = true;
            this.buttonMode = true;
            this.addEventListener(flash.events.MouseEvent.CLICK, this.onClick);
            return;
        }

        public set labelTxt(arg1: string)
        {
            this._labelTxt.text = arg1;
            this.textFormat = new GTextFormat(FontUtil.songtiName, 10, 16777215);
            this._labelTxt.setTextFormat(this.textFormat);
            return;
        }

        /* internal  */onClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (Cache.instance.trade.isTrading) 
            {
                MsgManager.showRollTipsMsg(Language.getString(41016));
            }
            else 
            {
                this.currentSbusiness = this._requestList.shift() as SBusiness;
                if (this._requestList.length == 0) 
                {
                    if (this.parent) 
                    {
                        this.parent.removeChild(this);
                        EffectManager.glowFilterUnReg(this);
                        this.dispatchEvent(new UIIconEvent(UIIconEvent.RemoveIcon));
                    }
                }
                this.labelTxt = String(this._requestList.length);
                Alert.show(Language.getStringByParam(41017, this.currentSbusiness.fromInfo.name), null, Alert.YES | Alert.NO, null, this.onAcceptTradeRequest);
            }
            return;
        }

        /* internal  */onAcceptTradeRequest(arg1: int): void
        {
            if (arg1 != Alert.YES) 
            {
                this.dispatchEvent(new DataEvent(GModuleEvent.Event_RejectTrade, this.currentSbusiness, false, true));
            }
            else 
            {
                this.dispatchEvent(new DataEvent(GModuleEvent.Event_AcceptTrade, this.currentSbusiness, false, true));
            }
            return;
        }

        public showHint(): void
        {
            this.show();
            this.labelTxt = String(this._requestList.length);
            return;
        }

        /* internal */ /* var */hintIcon: Object /* flash.display.Sprite */;

        public /* var */_requestList: Vector.<SBusiness>;

        /* internal */ /* var */currentSbusiness: SBusiness;

        /* internal */ /* var */_labelTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */textFormat: Object /* flash.text.TextFormat */;
    }
